<template>
	<view class="container">
		<!-- 状态栏 -->
		<view :class="statusBarViewClass"></view>
		<!-- 导航栏 -->
		<view class="customer-nav-view nav-sticky">
			<view class="customer-nav-left">
				<uni-icons type="back" color='#000000' size="24" @click="goBackPage"></uni-icons>
			</view>
			<view class="customer-nav-title">
				内容管理
			</view>
			<view class="customer-nav-right">
			</view>
		</view>
		<!-- 功能列表 -->
		<view class="content-item">
			<view class="content-item-left">
				<text class="text-left">青少年模式</text>
			</view>
			<view class="content-item-right" @click="changeErotic">
				<text class="text-right">{{userInfo && userInfo.config.appErotic == 1 ? '已关闭':'已开启'}}</text>
				<uni-icons type="right" size="16"></uni-icons>
			</view>
		</view>
	</view>
</template>

<script setup>
	import {
		onUnmounted,
		ref
	} from 'vue'
	import {
		onLoad,
		onShow
	} from '@dcloudio/uni-app'
	import {
		showToast,
		getUserInfo,
		clearUserInfo,
		setUserInfo,
		is18YearsOld,
		getUserToken
	} from '@/utils/utils.js'
	import api from '@/config/api'
	import request from '@/utils/request'

	const statusBarViewClass = ref("status-bar-view-2")
	const userInfo = ref(getUserInfo())

	// 青少年内容状态 即伦理内容
	const changeErotic = () => {
		let erotic = userInfo.value.config.appErotic
		erotic = erotic == 1 ? 2 : 1
		if (erotic == 1 && !is18YearsOld(userInfo.value.birthday)) {
			showToast('年龄未满18岁，禁止关闭！')
			return
		}
		request.post(api.host + api.updateUserErotic, {
			token: getUserToken(),
			erotic: erotic
		}).then(result => {
			if (result.success) {
				userInfo.value.config.appErotic = erotic
				userInfo.value.config.webErotic = erotic
				setUserInfo(userInfo.value)
				uni.reLaunch({
					url: '/pages/index/index'
				})
			}
		})
	}

	// 返回
	const goBackPage = () => {
		uni.navigateBack()
	}
</script>

<style lang="scss">
	@import url("manage_constent.css");
</style>